package net.sf.midollo.net.protocol.echo;

import net.sf.midollo.net.server.AsyncAcceptHandler;
import net.sf.midollo.net.server.InetServer;
import net.sf.midollo.utils.Utils;

public class Main {

	public static void main(String[] args) {
		try {
			String strLocalPort = null;
			for (int idx = 0; idx < args.length; ++idx) {
				if (args[idx].compareTo("-p") == 0) {
					if (++idx < args.length) {
						strLocalPort = args[idx];
					}
				}
			}

			int localPort = Utils.parseInt(strLocalPort, 0);

			EchoFactory protocolFactory = new EchoFactory();
			AsyncAcceptHandler acceptHandler = new AsyncAcceptHandler(protocolFactory);
			InetServer inetServer = new InetServer(localPort, acceptHandler);
			inetServer.run();

		} catch (Throwable ex) {
			ex.printStackTrace();
		}
	}
}
